<?php
namespace Cache;
use \Config,
      \Arr;
abstract class abstractCache implements ICache
{
    private $source;
    protected function setSource(array &$source)
    {
        $this->source = &$source;
    }
    public function get($props=null)
    {
        return is_null($props)? $this->source : Arr::get($this->source, $props);
    }
    
    public function set($props, $value, $switch=null)
    {
        if ('-f'===$switch || is_null($this->get($props)))
        {
            return Arr::set($this->source, $props, $value);
        }
        return false;
    }
    
    public function remove($props)
    {
        $props = preg_split('/\./', $props);
        $source = &$this->source;
        while ($key = current(array_splice($props, 0, 1)))
        {
            if ( ! isset($source[$key]))
            {
                break;
            }
            else if (empty($props))
            {
                unset($source[$key]);
            }
            $source = &$source[$key];
        }
    }
    
    public function clear()
    {
        foreach ((array)Config::get('cache.assign_clear') as $prop)
        {
            $this->remove($prop);
        }
    }
    
    public function clearAll()
    {
        $this->source = array();
    }
}
